package one.stand.service.impl;

import one.stand.enums.LoginEnum;
import one.stand.mapper.NoticeMapper;
import one.stand.model.NoticeModel;
import one.stand.model.ResultModel;
import one.stand.request.NoticeRequest;
import one.stand.response.NoticeResponse;
import one.stand.service.NoticeService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * @author: QIK
 * @CreateDate: 2019/5/28 15:13
 */
@Service
public class NoticeServiceImpl implements NoticeService {
    @Autowired
    protected NoticeMapper noticeMapper;
    
    @Override
    public ResultModel<List<NoticeResponse>> selectEffectiveList(NoticeRequest request) {
        LoginEnum loginEnum = LoginEnum.getByCode(request.getLoginProgramName());
        List<NoticeResponse> responseList = new ArrayList<>();
        List<NoticeModel> modelList = noticeMapper.selectEffectiveList(new NoticeModel() {{
            setNoticeType(loginEnum.getAccountType());
        }});
        modelList.forEach(m -> {
            {
                NoticeResponse response = new NoticeResponse();
                BeanUtils.copyProperties(m, response);
                responseList.add(response);
            }
        });
        return ResultModel.success(responseList);
    }
}
